#include "bsp_adc.h"
#include "main.h"

extern ADC_HandleTypeDef hadc1;

fp32 get_battery_voltage(void)
{
		static uint16_t adc_val[2];
		fp32 vbus;
	
		HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
		HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_val,2);
	
		vbus = (adc_val[0]*3.3f/65535)*11.0f;

    return vbus;
}
